﻿<cfsilent>
	<cfscript>
		
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		stringAdvice = getProperty("serviceFactory").getBean("stringAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		
		teacherId = sessionAdvice.getAutherUserID();
		
		taskType = event.getArg("TT");
		taskId = event.getArg("TSK");
		evsId = event.getArg("ES");
		secureTicket = event.getArg("ST");
		
		/* 安全设置 */
		viewSecure = false;
		
		/* 首先做安全检查 */
		try {
			stringOrignal = decrypt( secureTicket, teacherId, "PBEWithMD5AndDES", "Hex");
			stringTest = evsId & taskType & taskId;
			
			writeLog( text=stringOrignal );
			writeLog( text=stringTest );
			
			
			if ( stringOrignal eq stringTest ) {
				viewSecure = true;
			}
		}
		catch(any excpt) {
		}
		
		if ( viewSecure ) {
			
			sql = "SELECT 
						a.msg_id, 
						a.suggest, a.suggest_date, 
						a.reply, a.reply_date 
					FROM t_evaluate_comment a 
					WHERE 
						a.task_id = :taskId 
					ORDER BY a.suggest_date DESC";
			
			queryObj = new Query( datasource=application.dnsSlave );
			
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );

			rs_comment = queryObj.execute( sql=sql ).getResult();
			
			writelog( rs_comment.recordCount );
			
		}
		
	</cfscript>
</cfsilent>

<!---<div id="out"></div>--->

<cfif viewSecure >

	<cfif rs_comment.recordCount>

			<div class="mailContainer">
		
				<cfset row = 0 />
				<cfloop query="rs_comment">
			
					<cfset row++ />
					
					<cfset sign = encrypt( rs_comment.msg_id, teacherId, "PBEWithMD5AndDES", "Hex" ) />

					<div data-hash="<cfoutput>#sign#</cfoutput>" data-msg="<cfoutput>#rs_comment.msg_id#</cfoutput>" class="mailBox">
						
						<div class="index"><i><cfoutput>#row#</cfoutput></i></div>
						
						<div class="box">
							
							<div class="operation">
								<cfif rs_comment.reply eq "NOPE" >
									<a href="javascript:showReply('<cfoutput>#rs_comment.msg_id#</cfoutput>');">回复建议</a>
								</cfif>
							</div>

							<div class="main">
								<div class="header">
									<b>发送时间:</b> 
									<span class="numeric"><cfoutput>#datetimeAdvice.formatDatetimeString( rs_comment.suggest_date, "YYYY-MM-DD" )#</cfoutput></span>
								</div>
								<div class="message">
									<b>◆</b>
									<div><cfoutput>#stringAdvice.HTMLEncode( rs_comment.suggest )#</cfoutput></div>
								</div>
								
								<div class="reply <cfif rs_comment.reply eq "NOPE">hidden_elem</cfif>">
									<span class="bot2"></span>
									<span class="top2"></span>  
									<div><cfoutput>#stringAdvice.HTMLEncode( rs_comment.reply )#</cfoutput></div>
								</div>
								<div class="footer <cfif rs_comment.reply eq "NOPE">hidden_elem</cfif>">
									<b>回复时间:</b> 
									<span class="numeric"><cfoutput>#datetimeAdvice.formatDatetimeString( rs_comment.reply_date, "YYYY-MM-DD" )#</cfoutput></span>
								</div>
									
							</div>

						</div>
						
					</div>

				</cfloop>
	
			</div>
			
			<div class="mailForm hidden_elem">
				
				<form id="formReply" onSubmit="javascript:return processReply('formReply');" class="formWrapper" method="post">
					
					<input type="hidden" id="MSG" name="MSG" value="" />
					<input type="hidden" id="HASH" name="HASH" value="" />
					
					<div class="label">
						<b>学生建议</b>
						<div id="suggestContent"></div>
					</div>
					
					<div class="label">
						<b>教师回复</b>
						<textarea name="REPLY"></textarea>
					</div>
					
					<hr/>

					<div class="lable">
						<input class="button" type="submit" value="提交回复" />
						<a class="button2" href="javascript:cancelReply('formReply');">返回</a>
					</div>
				
				</form>
				
			</div>
			
			<script language="javascript" type="text/javascript">
				//<![CDATA[
				<!--
				function processReply( formId ) {

					var $form = $("form#" + formId);
					
					var msgId = $(":input[name='MSG']", $form).val();
					var msgHash = $(":input[name='HASH']", $form).val();
					var reply = $("textarea", $form).val();
					
					var re = /.+/;

					if ( re.test(reply) ) {

						/* 异步提交回复数据 */
						$.post(
								"<cfoutput>#buildURL('apiTaskReplySave')#</cfoutput>", 
								{
									"MSG": msgId, 
									"TSK": "<cfoutput>#taskId#</cfoutput>", 
									"REPLY": reply, 
									"Sign": msgHash, 
									"seed": (new Date()).getTime()
								}, 
								function(data){

									//$("#out").html(data);
									
									var result = $.parseJSON(data);

									if ( result.success ) {

										var $reply = $("div.reply", "div.mailBox[data-msg='" + msgId + "']");
										var $foot = $("div.footer", "div.mailBox[data-msg='" + msgId + "']");
										
										$("div", $reply).html( result.messageReply );
										$reply.removeClass("hidden_elem");
										
										$("span.numeric", $foot).html( result.messageDate );
										$foot.removeClass("hidden_elem");

										/* 重置表单 */
										$("#MSG").val("");
										$("#HASH").val("");
										$("textarea", $form).val("").removeClass("typeError");
										
										/* 显示意见和建议 */
										$("div.mailForm").addClass("hidden_elem");
										$("div.mailContainer").removeClass("hidden_elem");

									}
									else {
										alert("无法保存回复");
									}
									
								});
						
					}
					else {
						$("textarea", $form).addClass("typeError").focus();
					}
					
					return false;
				}
				
				function cancelReply( formId ) {
					
					var $form = $("form#" + formId);

					$("#MSG").val("");
					$("#HASH").val("");
					$("textarea", $form).val("").removeClass("typeError");
					
					$("div.mailForm").addClass("hidden_elem");
					$("div.mailContainer").removeClass("hidden_elem");
					
				}
				
				function showReply( msgId ) {
					
					var $message = $("div.mailBox[data-msg='" + msgId + "']");
					
					var msgHash = $message.attr("data-hash");
					var suggest = $("div.message > div", $message).text();
					
					$("#MSG").val( msgId );
					$("#HASH").val( msgHash );
					
					$("#suggestContent").html( suggest );
					
					$("div.mailContainer").addClass("hidden_elem");
					$("div.mailForm").removeClass("hidden_elem");
					
				}
				// -->
				//]]>
			</script>
		
		<cfelse>
			
			<div class="systemNotice">
				<p>还没有学生提交反馈信息</p>
			</div>
			
	</cfif>

</cfif>
